package com.taotao.service.Impl;

import com.taotao.common.resp.EasyUITreeNode;
import com.taotao.dao.ItemCatMapper;
import com.taotao.pojo.ItemCat;
import com.taotao.service.ItemCatService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by zzb on 2017/11/6.
 */

public class ItemCatServiceImpl implements ItemCatService {

    @Autowired
    private ItemCatMapper itemCatMapper;


    public List<EasyUITreeNode> getCatList(Long parentId) {

        List<EasyUITreeNode> nodes = new ArrayList<EasyUITreeNode>();

        List<ItemCat> itemCats = itemCatMapper.findByParentId(parentId);
        for(ItemCat itemCat : itemCats) {
            EasyUITreeNode node = new EasyUITreeNode();
            node.setId(itemCat.getId());
            node.setText(itemCat.getName());
            node.setState(itemCat.getIsParent()?"closed":"open");
            nodes.add(node);
        }

        return nodes;
    }
}
